<template>
  <!--批量调价-->
  <el-dialog title="批量调价" :visible.sync="dialogVisible" width="500px">
    <div>
      <el-form size="mini" :model="sendForm" label-width="100px" ref="sendForm" :rules="rules">
        <el-form-item label="类型：">
          <el-radio-group v-model="sendForm.type" prop="type">
            <el-radio label="add">增加</el-radio>
            <el-radio label="reduce">扣减</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="金额：" prop="price">
          <el-input-number size="medium" v-model="sendForm.price" :min="0"></el-input-number>
        </el-form-item>
      </el-form>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button @click="handleClose">取 消</el-button>
      <el-button type="primary" @click="handleConfirm" :loading="btnLoading">确 认</el-button>
    </span>
  </el-dialog>
</template>
<script>
import { batchEditPriceAPI } from '@/api/allInLine/inquiry.js'
import { mapGetters } from 'vuex'
import { Message } from 'element-ui';
const defaultSendForm = {
  type:"reduce",
  price: "",
  priceId:[],
};
export default {
  name: "addAdjustPrice",
  data() {
    return {
      dialogVisible: false,
      btnLoading: false,
      sendForm: JSON.parse(JSON.stringify(defaultSendForm)),
      rules: {
        type: [{ required: true, message: '请选择调价类型', trigger: 'change' }],
        price: [{ required: true, message: '请输入价格', trigger: 'blur' }],
      },
    }
  },
  computed: {
    ...mapGetters([
      'name',
      'mobile',
      'userId'
    ]),
  },
  components: {

  },
  created() {

  },
  filters: {

  },
  methods: {
    //显示弹框
    showPop(records) {
      this.dialogVisible = true;
      this.sendForm.priceId = [],
      this.sendForm=JSON.parse(JSON.stringify(defaultSendForm)),
      records.forEach((item) => {
        this.sendForm.priceId.push(item.priceId)
      })
    },
    //关闭弹框
    handleClose() {
      this.dialogVisible = false;
      this.$refs.sendForm.resetFields();
    },
    //确认新增
    handleConfirm() {
      let data=JSON.parse(JSON.stringify(this.sendForm))
      this.$refs.sendForm.validate((valid) => {
        if (valid) {
          this.btnLoading = true;
          batchEditPriceAPI(data).then((res) => {
              Message.success("提交成功");
              this.btnLoading = false;
              this.$emit("update");
              this.dialogVisible = false;
          }).catch(() => {
            this.btnLoading = false;
          })
        }
      })
    },
  },
}
</script>

<style  lang="scss"></style>
